﻿namespace UFIDA.U9.Cust.SH.SHFastShipBP
{
	using System;
	using System.Collections.Generic;
	using System.Text; 
	using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;
    using UFIDA.U9.CBO.SCM.Item;
    using UFIDA.U9.CBO.SCM.Warehouse;
    using UFSoft.UBF.Util.DataAccess;
    using UFIDA.U9.Base;
    using System.Data;
    using UFIDA.U9.CBO.MFG.BOM;
    using UFIDA.U9.Cust.SH.SHFastShipBP.SHFastShipBP;

	/// <summary>
	/// GetItemInfo partial 
	/// </summary>	
	public partial class GetItemInfo 
	{	
		internal BaseStrategy Select()
		{
			return new GetItemInfoImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class GetItemInfoImpementStrategy : BaseStrategy
	{
		public GetItemInfoImpementStrategy() { }

		public override object Do(object obj)
		{						
			GetItemInfo bpObj = (GetItemInfo)obj;
			
			//get business operation context is as follows
			//IContext context = ContextManager.Context	
			
			//auto generating code end,underside is user custom code
			//and if you Implement replace this Exception Code...
			//throw new NotImplementedException();

            if (bpObj.ItemQryList.Count <= 0)
                return null;

            List<ItemInfoDTO> retlist = new List<ItemInfoDTO>();

            foreach (ItemQryDTO dto in bpObj.ItemQryList)
            {
                ItemMaster item = ItemMaster.Finder.FindByID(dto.ItemID);
                if (item == null)
                    continue;
                ItemInfoDTO retdto = new ItemInfoDTO();
                retdto.ItemID = item.ID;
                retdto.ItemCode = item.Code;
                retdto.ItemName = item.Name;
                retdto.ItemSpec = item.SPECS;
                
                //获取仓库逻辑
                //优先单头仓库;单头没有仓库,取料品：销售页签：出货地点
                Warehouse wh = PubTool.GetDefaultWH(dto.WH, dto.ItemID,dto.CustID);
                if (wh != null)
                {
                    retdto.WH = wh.ID;
                    retdto.WHCode = wh.Code;
                    retdto.WHName = wh.Name;
                }

                //获取计量单位
                if (item.InventoryUOM != null)
                {
                    retdto.UOM = item.InventoryUOM.ID;
                    retdto.UOMCode = item.InventoryUOM.Code;
                    retdto.UOMName = item.InventoryUOM.Name;
                }

                //retdto.StoreQty = 5;
                //retdto.AvailableQty = 3;
                //设置库存数量、可用量
                PubTool.SetKitQty1(retdto);

                retdto.Qty = 1;
                retdto.Price = 0;
                retdto.Weight = item.Weight * retdto.Qty;

                retlist.Add(retdto);
            }

            return retlist;
		}
	}

	#endregion
	
	
}